package com.androidx.p013lv.mine.activity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.text.TextUtils;
import androidx.core.view.ViewCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.ImageUtil;
import com.androidx.p013lv.base.utils.QRCodeUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.bean.ShareBean;
import com.androidx.p013lv.mine.databinding.ActivityShareLayoutBinding;
import com.androidx.p013lv.mine.model.ShareModel;
import com.gyf.immersionbar.ImmersionBar;
import p000a.p002b.RxPermissions;
import p023io.reactivex.functions.Consumer;

/* renamed from: com.androidx.lv.mine.activity.ShareActivity */
public class ShareActivity extends BaseActivity<ActivityShareLayoutBinding> {
    private String invitationCode;
    private String link;
    private ShareModel model;
    public int videoId;

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityShareLayoutBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1207R.C1212layout.activity_share_layout;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ((ActivityShareLayoutBinding) this.binding).setClick(new OnClick());
        this.model = (ShareModel) new ViewModelProvider(this).get(ShareModel.class);
        this.invitationCode = SpUtils.getInstance().getUserInfo().getInviteCode();
        ((ActivityShareLayoutBinding) this.binding).setInvitationCode(this.invitationCode);
        this.model.shareData(this.videoId, this).observe(this, new Observer<BaseRes<ShareBean>>() {
            /* class com.androidx.p013lv.mine.activity.ShareActivity.C12711 */

            public void onChanged(BaseRes<ShareBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    ShareActivity.this.link = baseRes.getData().getUrl();
                    ((ActivityShareLayoutBinding) ShareActivity.this.binding).f330a.setImageBitmap(QRCodeUtil.createQRCode(ShareActivity.this.link, 400));
                    String[] split = ShareActivity.this.link.split("\\?");
                    if (split.length > 0) {
                        ((ActivityShareLayoutBinding) ShareActivity.this.binding).setLink(split[0]);
                        return;
                    }
                    return;
                }
                ToastUtils.getInstance().showWrong(UiUtils.getString(C1207R.string.hit_no_net));
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void requestPermission(final Bitmap bitmap) {
        if (Build.VERSION.SDK_INT >= 23) {
            new RxPermissions(this).request("android.permission.WRITE_EXTERNAL_STORAGE").subscribe(new Consumer<Boolean>() {
                /* class com.androidx.p013lv.mine.activity.ShareActivity.C12722 */

                public void accept(Boolean bool) throws Exception {
                    if (bool.booleanValue()) {
                        ImageUtil.saveImageToGallery(ShareActivity.this, bitmap);
                    } else {
                        ToastUtils.getInstance().showSigh("未授權權限，請在設置中允許權限");
                    }
                }
            });
        } else {
            ImageUtil.saveImageToGallery(this, bitmap);
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        ShareModel shareModel = this.model;
        if (shareModel != null) {
            shareModel.cancelHttp();
        }
        super.onDestroy();
    }

    /* renamed from: com.androidx.lv.mine.activity.ShareActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            ShareActivity.this.finish();
        }

        public void saveLinkBtn() {
            if (!ShareActivity.this.isOnClick()) {
                if (TextUtils.isEmpty(ShareActivity.this.link)) {
                    ToastUtils.getInstance().showWrong("鏈接錯誤");
                } else if (!UiUtils.copyContentClipboard(ShareActivity.this.link)) {
                    ToastUtils.getInstance().showWrong("復制失敗");
                } else {
                    ToastUtils.getInstance().showCorrect("復制成功");
                }
            }
        }

        public void saveImgBtn() {
            if (!ShareActivity.this.isOnClick()) {
                if (TextUtils.isEmpty(ShareActivity.this.link)) {
                    ToastUtils.getInstance().showWrong("鏈接錯誤");
                    return;
                }
                Bitmap copy = ((BitmapDrawable) ShareActivity.this.getResources().getDrawable(C1207R.C1209drawable.mine_bg_share_two)).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
                Canvas canvas = new Canvas(copy);
                Bitmap createQRCode = QRCodeUtil.createQRCode(ShareActivity.this.link, 400);
                float width = ((float) copy.getWidth()) / 3.0f;
                float height = (((float) copy.getHeight()) - width) / 2.0f;
                float height2 = ((((float) copy.getHeight()) - width) / 2.0f) + width;
                RectF rectF = new RectF((((float) copy.getWidth()) - width) / 2.0f, height, ((((float) copy.getWidth()) - width) / 2.0f) + width, height2);
                Paint paint = new Paint();
                paint.setAntiAlias(true);
                canvas.drawBitmap(createQRCode, (Rect) null, rectF, paint);
                Bitmap copy2 = ((BitmapDrawable) ShareActivity.this.getResources().getDrawable(C1207R.C1209drawable.mine_bg_share_link_two)).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
                float width2 = (float) copy2.getWidth();
                float width3 = ((((float) copy.getWidth()) - width2) / 2.0f) + ((float) UiUtils.dp2px(5));
                float dp2px = ((float) UiUtils.dp2px(14)) + height2;
                float width4 = ((((float) copy.getWidth()) - width2) / 2.0f) + width2 + ((float) UiUtils.dp2px(10));
                float dp2px2 = height2 + ((float) UiUtils.dp2px(14)) + ((float) copy2.getHeight());
                canvas.drawBitmap(copy2, (Rect) null, new RectF(width3, dp2px, width4, dp2px2), paint);
                Paint paint2 = new Paint();
                paint2.setAntiAlias(true);
                paint2.setColor(-1);
                paint2.setTextSize((float) UiUtils.dp2px(12));
                String[] split = ShareActivity.this.link.split("\\?");
                float width5 = width3 + ((((float) copy2.getWidth()) - paint2.measureText(split[0])) / 2.0f);
                canvas.drawText(split[0], width5 + ((float) UiUtils.dp2px(8)), (dp2px2 - (((float) (copy2.getHeight() - UiUtils.dp2px(14))) / 2.0f)) - ((float) UiUtils.dp2px(2)), paint2);
                paint2.setTextSize((float) UiUtils.dp2px(18));
                float width6 = (((float) copy.getWidth()) - paint2.measureText("邀請碼：" + ShareActivity.this.invitationCode)) / 2.0f;
                paint2.setColor(ViewCompat.MEASURED_STATE_MASK);
                canvas.drawText("邀請碼：", width6, height - ((float) UiUtils.dp2px(30)), paint2);
                paint2.setColor(ShareActivity.this.getResources().getColor(C1207R.C1208color.btnRedColor));
                canvas.drawText(ShareActivity.this.invitationCode, width6 + paint2.measureText("邀請碼："), height - ((float) UiUtils.dp2px(30)), paint2);
                ShareActivity.this.requestPermission(copy);
            }
        }
    }
}
